var maxMoves = function(grid) {
    const m =grid.length
    const n =grid[0].length
    let ans=0
    function dfs(i,j){
        ans=Math.max(ans,j)
        if(ans === n-1){
            return;
        }
        for(let k=Math.max(i-1,0);k<Math.min(i+2,m);k++){
            if(grid[k][j+1]>grid[i][j]){
                dfs(k,j+1)
            }
        }
        grid[i][j]=0
    }
    for(let i =0;i<m;i++){
        dfs(i,0)
    }
    return ans
};

